#!/usr/bin/python

# include the contrib config file
import build_contrib
import os
import shutil

# set pkg info
PKG_NAME="wxWidgets"
PKG_VERSION="2.9.3"
PKG_ARCHIVE="tar.bz2"

#
build_contrib.begin_build(PKG_NAME, PKG_VERSION)
build_contrib.do_extract(PKG_NAME, PKG_VERSION, PKG_ARCHIVE)
build_contrib.do_patch(PKG_NAME, PKG_VERSION)

# configure
if build_contrib.pushd("%s/%s-%s" % (build_contrib.BUILD_PREFIX, PKG_NAME, PKG_VERSION)) != 0: exit( 1 )
if build_contrib.TARGET_SYSTEM_NAME == "windows":
	pass
else:
	if os.system("./configure --prefix=%s" % build_contrib.INSTALL_PREFIX) != 0 : build_contrib.popd_and_exit()
build_contrib.popd()


# build & install
if build_contrib.pushd("%s/%s-%s" % (build_contrib.BUILD_PREFIX, PKG_NAME, PKG_VERSION)) != 0: exit( 1 )
if build_contrib.TARGET_SYSTEM_NAME == "windows":
	if build_contrib.pushd("build/msw/") != 0: exit( 1 )
	if os.system("nmake -f makefile.vc") != 0: build_contrib.popd_and_exit()
	build_contrib.popd()
	try:
		lib_postfix = ""
		if build_contrib.CMAKE_BUILD_TYPE == "Debug": lib_postfix = "d"
		build_contrib.recursive_copy("./lib/vc_lib/wxbase29u%s.lib" % lib_postfix, "%s/lib/wxbase29u%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxbase29u%s_xml.lib" % lib_postfix, "%s/lib/wxbase29u%s_xml.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxbase29u%s_net.lib" % lib_postfix, "%s/lib/wxbase29u%s_net.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxexpat%s.lib" % lib_postfix, "%s/lib/wxexpat%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxjpeg%s.lib" % lib_postfix, "%s/lib/wxjpeg%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_adv.lib" % lib_postfix, "%s/lib/wxmsw29u%s_adv.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_aui.lib" % lib_postfix, "%s/lib/wxmsw29u%s_aui.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_core.lib" % lib_postfix, "%s/lib/wxmsw29u%s_core.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_gl.lib" % lib_postfix, "%s/lib/wxmsw29u%s_gl.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_html.lib" % lib_postfix, "%s/lib/wxmsw29u%s_html.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_media.lib" % lib_postfix, "%s/lib/wxmsw29u%s_media.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_propgrid.lib" % lib_postfix, "%s/lib/wxmsw29u%s_propgrid.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_qa.lib" % lib_postfix, "%s/lib/wxmsw29u%s_qa.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_ribbon.lib" % lib_postfix, "%s/lib/wxmsw29u%s_ribbon.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_richtext.lib" % lib_postfix, "%s/lib/wxmsw29u%s_richtext.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_stc.lib" % lib_postfix, "%s/lib/wxmsw29u%s_stc.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_webview.lib" % lib_postfix, "%s/lib/wxmsw29u%s_webview.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxmsw29u%s_xrc.lib" % lib_postfix, "%s/lib/wxmsw29u%s_xrc.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxpng%s.lib" % lib_postfix, "%s/lib/wxpng%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxregexu%s.lib" % lib_postfix, "%s/lib/wxregexu%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxscintilla%s.lib" % lib_postfix, "%s/lib/wxscintilla%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxtiff%s.lib" % lib_postfix, "%s/lib/wxtiffd%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./lib/vc_lib/wxzlib%s.lib" % lib_postfix, "%s/lib/wxzlib%s.lib" % (build_contrib.INSTALL_PREFIX, lib_postfix))
		build_contrib.recursive_copy("./include/wx", "%s/include/wx-2.9/wx" % build_contrib.INSTALL_PREFIX)
		build_contrib.recursive_copy("./lib/vc_lib/mswud", "%s/lib/mswud" % build_contrib.INSTALL_PREFIX)
	except:
		build_contrib.popd_and_exit()
else:
	if os.system("make") != 0: build_contrib.popd_and_exit()
	if os.system("make install") != 0: build_contrib.popd_and_exit()
build_contrib.popd()

# end
build_contrib.end_build(PKG_NAME, PKG_VERSION)
